//
//  PSCell.swift
//  PhotoSetSwift
//
//  Created by 金玉龙 on 15/12/18.
//  Copyright © 2015年 jinyulong. All rights reserved.
//

import UIKit

class PSCell: UITableViewCell {

    let titleLabel = UILabel.init()
    let timeLabel = UILabel.init()
    let leftImgView = UIImageView.init()
    let middleImgView = UIImageView.init()
    let rightImgView = UIImageView.init()
    let bgView = UIView.init()

    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCellSelectionStyle.None
        initCompnent()
        layoutCompnent()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    deinit{
        
    }
    private func initCompnent(){
        self .addSubview(titleLabel);
        self .addSubview(timeLabel)
        bgView.backgroundColor = UIColor.clearColor()
        self .addSubview(bgView)
        bgView .addSubview(leftImgView)
        bgView .addSubview(middleImgView)
        bgView .addSubview(rightImgView)
        leftImgView.backgroundColor = UIColor.redColor()
        middleImgView.backgroundColor = UIColor.redColor()
        rightImgView.backgroundColor = UIColor.redColor()
        weak var weakSelf = self;
        bgView .snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(weakSelf!).inset(UIEdgeInsetsMake(10, 10, 0, 10))
        }
    }
    func layoutCompnent(){
        titleLabel .snp_makeConstraints { (make) -> Void in
            make.left.equalTo(bgView).offset(7);
            make.right.equalTo(bgView).offset(-5);
            make.top.equalTo(bgView).offset(7);
            make.bottom.equalTo(timeLabel.snp_top).offset(-7);
        }
        
        timeLabel .snp_makeConstraints { (make) -> Void in
            make.left.right.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp_bottom).offset(7)
            make.bottom.equalTo(leftImgView.snp_top).offset(-10)
        }
        
        leftImgView .snp_makeConstraints { (make) -> Void in
            make.top.equalTo(timeLabel.snp_bottom).offset(10);
            make.left.equalTo(bgView).offset(7);
            make.right.equalTo(middleImgView.snp_left).offset(-5);
            make.bottom.equalTo(bgView).offset(-10);
            make.width.equalTo(middleImgView.snp_width);
            make.height.equalTo(83);
        }
        
        middleImgView .snp_makeConstraints { (make) -> Void in
            make.top.width.height.bottom.equalTo(leftImgView)
            make.left.equalTo(leftImgView.snp_right).offset(5)
            make.right.equalTo(rightImgView.snp_left).offset(-5)
        }

        rightImgView .snp_makeConstraints { (make) -> Void in
            make.top.bottom.width.height.equalTo(middleImgView)
            make.left.equalTo(middleImgView.snp_right).offset(5)
            make.right.equalTo(bgView).offset(-7)

        }
    }
    
    func constrantWithVFL(VFL VFL :String , views : [String : AnyObject] ) ->[NSLayoutConstraint]{
        return NSLayoutConstraint .constraintsWithVisualFormat(VFL, options: NSLayoutFormatOptions.AlignAllBaseline, metrics: nil , views: views);
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
